<template>
    <div class="app-container">
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="当前状态">
                        <label>{{enterpriseInfo0.status == 2?'审核通过':(enterpriseInfo0.status == 1?'未审核通过':'未审核')}}</label>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="16">
                    <el-form-item class="checkbtn">
                        <span class="tips">{{tips}} &nbsp;&nbsp;</span>
                        <el-button @click="auditEnterpriseInfo(2)" v-show="this.deleted === 0 && enterpriseInfo0.status !== 2 ? true:false"><icon-svg icon-class="save"></icon-svg>&nbsp;&nbsp;审核通过</el-button>
                        <el-button @click="auditEnterpriseInfo(1)" v-show="this.deleted === 0 && enterpriseInfo0.status !== 2 ? true:false"><icon-svg icon-class="del"></icon-svg>&nbsp;&nbsp;审核不通过</el-button>
                        <el-button @click="backToList()">返回列表</el-button>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="账号信息">
                        <div>{{enterpriseInfo0.username}}</div>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="企业网址">
                        <div>{{enterpriseInfo0.website||'无'}}</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="企业名称">
                        <div>{{enterpriseInfo1.enterprisename||'无'}}</div>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="验证码数">
                        <div>{{enterpriseInfo1.fakenumber||'无'}}</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="联系方式">
                        <div>{{enterpriseInfo2.enterprisephone||'无'}}</div>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="企业法人">
                        <div>{{enterpriseInfo2.owner||'无'}}</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="24" :md="24" :lg="20">
                    <el-form-item label="法定地址">
                        <div>{{destructionPositionAddress(enterpriseInfo3.addressPositionList) + '' + enterpriseInfo3.address||'暂无详细地址信息'}}</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="24" :md="24" :lg="20">
                    <el-form-item label="生产地址">
                        <div>{{destructionPositionAddress(enterpriseInfo4.productionAddressPositionList) + '' + enterpriseInfo4.productionAddr||'暂无详细地址信息'}}</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="24" :md="24" :lg="22">
                    <el-form-item label="经营范围">
                        <div>{{enterpriseInfo5.scope||'无'}}</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="12" :md="8" :lg="8">
                    <el-form-item label="营业执照">
                        <img v-if="imageUrlLicense" :src="imageUrlLicense" class="avatar">
                        <div v-else class="noimage">暂无营业执照</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="24" :md="24" :lg="22">
                    <el-form-item label="服务信息">
                        <div>{{enterpriseInfo6.serviceinformation||'无'}}</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="12" :md="8" :lg="8">
                    <el-form-item label="企业logo">
                        <img v-if="imageUrlLogo" :src="imageUrlLogo" class="avatar">
                        <div v-else class="noimage">暂无企业logo</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="24" :md="24" :lg="22">
                    <el-form-item label="公司简介">
                        <div>{{enterpriseInfo7.enterpriseprofile||'无'}}</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true">
                <el-col :xs="24" :sm="12" :md="8" :lg="8">
                    <el-form-item label="宣传视频">
                        <video v-if="imageUrlVideo" :src="imageUrlVideo" controls="controls" class="vediocss">
                               您的浏览器不支持 video 标签
                        </video>
                        <div v-else class="noimage">暂无企业宣传视频</div>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
    </div>
</template>

<style scoped>
.selectOther {
    width: 130px;
}

.selectUser {
    width: 250px;
}

.detailAddr {
    width: 155px;
}

.plainInput {
    width: 250px;
}

.bussinessScope {
    width: 250px;
    overflow: auto;
    word-break: break-all;
}

.businessLicense {
    width: 250px;
    height: 178px;
    border: 1px dashed #d9d9d9;
}

.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #20a0ff;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 250px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}

.avatar {
    width: 250px;
    height: 178px;
    display: block;
}

.operateBtn {
    text-align: center;
    margin: 0 auto;
}

.tips {
    font-size: 14px;
    color: red;
}

.vediocss {
    background-color: black;
    height: 178px;
    width: 250px;
}

.checkbtn {
    float: right;
}
</style>

<script>
import { auditEnterprise } from 'api/enterprise';

export default {
    data() {
        return {
            enterpriseInfo7: {
                enterpriseprofile: '',
                video: ''
            },
            enterpriseInfo6: {
                serviceinformation: '',
                logo: ''
            },
            enterpriseInfo5: {
                scope: '',
                businesslicense: ''
            },
            enterpriseInfo4: {
                productionaddressid: '',
                productionAddr: '',
                productionAddressPositionList: ''
            },
            enterpriseInfo3: {
                addressid: '',
                address: '',
                addressPositionList: ''
            },
            enterpriseInfo2: {
                enterprisephone: '',
                owner: ''
            },
            enterpriseInfo1: {
                enterpriseid: null,
                enterprisename: '',
                fakenumber: null
            },
            enterpriseInfo0: {
                userid: null,
                username: '',
                userType: '',
                website: '',
                status: 0
            },
            imageUrlLicense: '',
            imageUrlLogo: '',
            imageUrlVideo: '',
            tips: '',
            position0: {
                province: {
                    list: [],
                    isEnable: false
                },
                city: {
                    list: [],
                    isEnable: true
                },
                county: {
                    list: [],
                    isEnable: true
                },
                town: {
                    list: [],
                    isEnable: true
                },
                village: {
                    list: [],
                    isEnable: true
                }
            },
            position1: {
                province: {
                    list: [],
                    isEnable: false
                },
                city: {
                    list: [],
                    isEnable: true
                },
                county: {
                    list: [],
                    isEnable: true
                },
                town: {
                    list: [],
                    isEnable: true
                },
                village: {
                    list: [],
                    isEnable: true
                }
            },
            province0: '',
            city0: '',
            county0: '',
            town0: '',
            village0: '',
            province1: '',
            city1: '',
            county1: '',
            town1: '',
            village1: '',
            deleted: 0
        }
    },
    created() {
        // 表单初始化
        let enterprise = this.$route.query.enterpriseinfo;
        this.deleted =  this.$route.query.deleted;
        this.enterpriseInfo7.enterpriseprofile = enterprise.enterpriseprofile || '',
        this.enterpriseInfo7.video = enterprise.video || '',
        this.imageUrlVideo = enterprise.videoURL || '',
        this.enterpriseInfo6.serviceinformation = enterprise.serviceinformation || '',
        this.enterpriseInfo6.logo = enterprise.logo || '',
        this.imageUrlLogo = enterprise.logoURL || '',
        this.enterpriseInfo5.scope = enterprise.scope || '',
        this.imageUrlLicense = enterprise.businesslicenseURL || '',
        this.enterpriseInfo5.businesslicense = enterprise.businesslicense || '',
        this.enterpriseInfo4.productionaddressid = enterprise.productionaddressid || '',
        this.enterpriseInfo4.productionAddr = enterprise.productionaddress || '',
        this.enterpriseInfo4.productionAddressPositionList = enterprise.productionAddressPositionList || '',
        this.enterpriseInfo3.addressid = enterprise.addressid || '',
        this.enterpriseInfo3.address = enterprise.address || '',
        this.enterpriseInfo3.addressPositionList = enterprise.addressPositionList || '',
        this.enterpriseInfo2.enterprisephone = enterprise.enterprisephone || '',
        this.enterpriseInfo2.owner = enterprise.owner || '',
        this.enterpriseInfo1.enterpriseid = enterprise.enterpriseid || '',
        this.enterpriseInfo1.enterprisename = enterprise.enterprisename || '',
        this.enterpriseInfo1.fakenumber = enterprise.fakenumber || '',
        this.enterpriseInfo0.userid = enterprise.userid || '',
        this.enterpriseInfo0.username = enterprise.username || '',
        this.enterpriseInfo0.userType = enterprise.userType || '',
        this.enterpriseInfo0.website = enterprise.website || '',
        this.enterpriseInfo0.status = enterprise.status || ''
    },
    methods: {
        // 解析生产地址信息
        destructionPositionAddress(positionAddress) {
            let addr = positionAddress;
            let resAddr = '';
            if ( addr.length > 0 ) {
               for (var i = 0; i < addr.length; i++) {
                   resAddr += addr[i].name
               }
            }
            return resAddr;    
        },
        // 审核企业信息
        auditEnterpriseInfo(status) {
            let requestParam = {
                enterpriseid: this.enterpriseInfo1.enterpriseid || '',
                status: status || 0
            }
            auditEnterprise(requestParam).then(Response => {
                let res = Response.data;
                if (res.flag === 1) {
                    this.enterpriseInfo0.status = status;
                    this.tips = '审核操作成功'
                }else {
                    this.tips = '审核操作失败';
                }
            })
        },
        backToList() {
            this.$router.go(-1)
        }
    }
};
</script>